package com.demo.springBootDemo02.web;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.env.Environment;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class IndexController {

	@Autowired
	private Environment env;

	@Value("${runtime_ftpIp}")
	private String ftpIp;
	@Value("${runtime_ftpUsername}")
	private String ftpUsername;
	@Value("${runtime_ftpPassword}")
	private String ftpPassword;

	@RequestMapping("/")
	public Object index() {
		return "welcome";
	}

	@RequestMapping("/hello/{name}")
	public Object hello(@PathVariable("name") String name) {
		return String.format("Hello,%s", name);
	}

	@RequestMapping("/runtime")
	public Object runtime() {
		String strFromEnv = String.format("Env(ftpIp=%s,ftpUsername=%s,ftpPassword=%s)",
				env.getProperty("runtime_ftpIp"), env.getProperty("runtime_ftpUsername"),
				env.getProperty("runtime_ftpPassword"));
		String strFromInject = String.format("@Value(ftpIp=%s,ftpUsername=%s,ftpPassword=%s)", ftpIp, ftpUsername,
				ftpPassword);
		return strFromEnv + strFromInject;
	}

}
